package com.sina.shop.dao.card;

import com.sina.shop.dao.ShopDataSourceDao;
import com.sina.shop.domain.card.Card;
import org.hibernate.query.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * 段浩杰   2018-02-05-14:19
 */
@Repository("cardDao")
public class CardDaoImpl extends ShopDataSourceDao implements CardDao {

    @Override
    public List<Card> getCardListByAdminId(Long adminId) {
        String hql = "from Card c where c.admin.id= :adminId";
        return list(hql, new String[]{"adminId"}, new Object[]{adminId}, -1, -1);
    }

    @Override
    public Integer deleteCard(Long id) {
        String hql = "delete from Card c where c.id = :id";
        return template.executeWithNativeSession(session -> {
            Query query = session.createQuery(hql);
            query.setParameter("id", id);

            return query.executeUpdate();
        });
    }
}
